﻿using System;
using System.Linq;
using TestWebApplication.CommerceTransaction;
using Microsoft.Commerce.Proxy.TransactionService.v201001;
using CommerceAccountProxy = Microsoft.Commerce.Proxy.AccountService;

namespace TestWebApplication.CommerceTestDataProvider
{
    public class CommerceTransactionDataProvider
    {

        public static CallerInfo CreateCallerInfo(CommerceAccountProxy.Identity identity, string acccountId)
        {
            Identity requester = new Identity()
            {
                IdentityType = identity.IdentityType,
                IdentityValue = identity.IdentityValue,
            };
            requester.IdentityProperty = identity.IdentityProperty == null ? null : identity.IdentityProperty.Select(
                x => new Property()
                {
                    Name = x.Name,
                    Value = x.Value,
                    Namespace = x.Namespace
                }).ToArray();

            CallerInfo ret = new CallerInfo()
            {
                Requester = requester,
                AccountId = acccountId,
            };
            return ret;
        }

        public static Identity CreateRandomIdentity()
        {
            // we only create "PUID" identity type here
            Puid puid = Puid.RandomPuid();
            Identity identity = new Identity();
            identity.IdentityType = "PUID";
            identity.IdentityValue = puid.ToString();

            identity.IdentityProperty = new[]
            {
                new Property
                {
                    Name = "PassportMemberName",
                    Value = GlobalRandom.CreateAlphabeticString(10) + "@live.com"
                }
            };

            return identity;
        }

    }
}
